package com.wk.design.stragy;

/**
 * 策略
 * @author wukai
 * @date 2023/6/7 14:04
 */
public enum SaveEnum {
    DB("db"){
        @Override
        public void save(String data) {
            System.out.println("保存到数据库");
        }
    },
    FILE("file"){
        @Override
        public void save(String data) {
            System.out.println("保存到文件");
        }
    }
    ;
    private String type;
    public abstract void save(String data);
    SaveEnum(String type){
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public static void saveData(String type, String data){
        for (SaveEnum value : values()) {
            if(value.getType().equalsIgnoreCase(type)){
                value.save(data);
            }
        }
    }
}
